<?php
/**
 * This file will find all data stored and deliver it as an xml-file.
 * Note that the HTML have to be all the way to the left
 * screwing up the formation.
 * 
 * @version 1.0
 * 
 * @todo DB-file to simplify db-connection.
 * @todo Some kind of controll to make sure not to show empty signals.
 * $todo Make it object-oriented.
 */

$dsn      = 'mysql:dbname=chalmersveratea;host=chalmersverateam.se.mysql';
$user     = 'chalmersveratea';
$password = 'ygfxAGej';
$dbh      = new PDO($dsn, $user, $password);

header( 'Content-type: text/xml' );//Set header to XML.

echo  <<<HTML
<LoggData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="TestSchema.xsd">
HTML;
for($j = 1; $j < 31; $j++) { //Go through all 30 values.
	$sql      = "SELECT * FROM Log_Data WHERE signalID = ".$j;

	$stmt = $dbh->prepare($sql);
	$stmt->execute();
	echo  <<<HTML

	<signal id="{$j}">
HTML;
	while ($row = $stmt->fetch()) {//All values for each siganalID
		echo  <<<HTML
	    <signalData>
	        <signalValue>{$row['signalValue']}</signalValue>
	        <time>2{$row['inputDate']}</time>
	        <xCoordinate>{$row['x_coordinate']}</xCoordinate>
	        <yCoordinate>{$row['y_coordinate']}</yCoordinate>
	        <warning>{$row['warning']}</warning>
	    </signalData>
HTML;
	}
	echo "</signal>";
}
echo "</LoggData>";
?>